package com.rp.system.dao;

import java.util.List;

import org.raptor.common.DbOperUtil;
import org.raptor.orm.hibernate.DbaHibernateTemplateSupport;
import org.raptor.pagination.Page2;
import org.springframework.stereotype.Repository;

import com.rp.common.vo.PageParam;
import com.rp.system.po.Module;

@Repository
public class ModuleDao extends DbaHibernateTemplateSupport<Module> {

	public static final String INSERT_MODULE = 
			"INSERT INTO RP_SYSTEM_MODULES(id,createDate,updateDate,version,name,parentId,remark,rescNum) " +
			"VALUES(?,?,?,?,?,?,?,?)";
	
	/**
	 * 分页获取模块数据
	 * @param pageParam
	 * @param name 查询参数name
	 * @return
	 */
	public Page2 getModulesByPage(PageParam pageParam, String name){
		String hql = "from Module where name like ?";
		return this.getPage2ByOffset(hql, 
				pageParam.getPageOffset(), pageParam.getPageSize(),
				pageParam.getSortField(), pageParam.getSortOrder(),
				DbOperUtil.fuzzyQueryParam(name));
	}
	
	
	public List<Module> getModules(PageParam pageParam, String name){
		String hql = "from Module where name like ?"
				+DbOperUtil.generateOrderBy(pageParam.getSortField(), pageParam.getSortOrder());
		return this.find(hql, DbOperUtil.fuzzyQueryParam(name));
	}
	
	/**
	 * 根据名称查找模块列表
	 * @param name
	 * @return
	 */
	public List<Module> getModulesByName(String name){
		String hql = "from Module where name like ?";
		return this.find(hql, DbOperUtil.fuzzyQueryParam(name));
	}
	
}
